package lego.jbv;

import lego.animal.IAnimal;
import lejos.nxt.LCD;

public class Display {
	private final static String NAME = "Name";
	private final static String LIFE = "Life";
	private final static String STAMINA = "Stamina";
	private static IAnimal animal;
	private static String status;
	
	public static void init(IAnimal animal)
	{
		Display.animal = animal;
		status = "";
		redraw();
	}
	
	public static void setLife(int life)
	{
		Display.animal.setLife(life);
		redraw();
	}
	
	public static void setStamina(int stamina)
	{
		Display.animal.setStamina(stamina);
		redraw();
	}
	
	public static void setStatus(String text)
	{
		StringBuilder sb = new StringBuilder();
		
		if(text.length() <= 16)
		{
			int spaces = (16-text.length())/2;
			for(int i = 0; i < spaces; i++)
			{
				sb.append(" ");
			}
			
			sb.append(text.toUpperCase());
		}
		
		else
		{
			sb.append(text);
			sb.delete(15, sb.length());
		}
		
		status = sb.toString();
		
		redraw();
	}
	
	private static void redraw()
	{
		LCD.clear();
		
		if(Display.animal != null)
		{
			LCD.drawString(NAME + ":", 0, 0);
			LCD.drawString(Display.animal.getName(), NAME.length() + 2, 0);
			
			LCD.drawString(LIFE + ":", 0, 1);
			LCD.drawInt(Display.animal.getLife(), 3, 12, 1);
			
			LCD.drawString(STAMINA + ":", 0, 2);
			LCD.drawInt(Display.animal.getStamina(), 3, 12, 2);
		}
		
		LCD.drawString("----------------", 0, 6);
		LCD.drawString(status, 0, 7);
	}
	
	public static int getLife()
	{
		if(Display.animal != null)
		{
			return animal.getLife();
		}
		
		return -1;
	}
	
	public static int getStamina()
	{
		if(Display.animal != null)
		{
			return animal.getStamina();
		}
		
		return -1;
	}
	
	public static int getNormalSpeed()
	{
		if(Display.animal != null)
		{
			return animal.getNormalSpeed();
		}
		
		return -1;
	}
	
	public static int getBurstSpeed()
	{
		if(Display.animal != null)
		{
			return animal.getBurstSpeed();
		}
		
		return -1;
	}
	
	public static int getStaminaHighBound()
	{
		if(Display.animal != null)
		{
			return animal.getStaminaHighBound();
		}
		
		return -1;
	}
	
	public static int getStaminaLowBound()
	{
		if(Display.animal != null)
		{
			return animal.getStaminaLowBound();
		}
		
		return -1;
	}
}
